package cn.gok.homework;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


class Book {
    private int bid;
    private String name;
    private float price;

    private void sell() {
        System.out.println(this.name + "被卖了");
    }

    private void sell(float price, String person) {
        System.out.println(this.name + "卖给了" + person + ",卖了" + price + "元");
    }

    public Book(int bid, String name, float price) {
        this.bid = bid;
        this.name = name;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Book{" +
                "bid=" + bid +
                ", name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
}

public class HomeWork {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class c = Book.class;
        Constructor constructor = c.getConstructor(int.class, String.class, float.class);
        Book book = (Book) constructor.newInstance(1, "xxx", 2000f);
        Method method1 = c.getDeclaredMethod("sell");
        Method method2 = c.getDeclaredMethod("sell", float.class, String.class);
        method1.setAccessible(true);
        method2.setAccessible(true);
        method1.invoke(book);
        method2.invoke(book, 1000f, "小林");
    }
}
